package com.zhuxulin.java.email.fildder;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 
 * @author ZhuXulin <br>
 *         此包主要用来解析Fildder导出的文件获取QQ邮箱 格式如下：<br>
 *         GET http://cgi.pub.qq.com/report/report_vm?tag=0&log=
 *         fuz_10875_87705319_201406162035 HTTP/1.1<br>
 *         Host: cgi.pub.qq.com<br>
 *         Connection: keep-alive<br>
 *         Accept: image/webp,*\/*;q=0.8<br>
 *         User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
 *         (KHTML, like Gecko) Chrome/29.0.1547.59 QQ/5.5.11447.201
 *         Safari/537.36<br>
 *         Referer:
 *         http://find.qq.com/index.html?version=1&im_version=5335&width
 *         =910&height=610&search_target=0<br>
 *         Accept-Encoding: gzip,deflate<br>
 *         Accept-Language: en-us,en<br>
 *         Cookie: RK=4YvvWuvlSQ; pt2gguin=o0379269087; uin=o0379269087;
 *         skey=@37xUGcEdH; ptisp=ctc; ptcz=
 *         c54541172794df69fe5a80a4b600d933294bb4c161d3a3179fc1320b0338b900;
 *         pgv_info=ssid=s9159393236; pgv_pvid=4293741024<br>
 * <br>
 * <br>
 *         HTTP/1.1 200 OK<br>
 *         Server: tws<br>
 *         Date: Sun, 22 Jun 2014 12:12:48 GMT<br>
 *         Content-Type: application/json;charset=utf-8<br>
 *         Content-Length: 8<br>
 *         Connection: close<br>
 * <br>
 *         {"ec":0}<br>
 * <br>
 *         ------------------------------------------------------------------<br>
 */
public class LineHandler implements ILineHanlder {
	private Set<String> QQNumberSet = new HashSet<String>();

	public Set<String> getQQNumberSet() {
		return QQNumberSet;
	}

	public void setQQNumberSet(Set<String> qQNumberSet) {
		QQNumberSet = qQNumberSet;
	}

	@Override
	public void onReadStart(String line, int num) {
		if (line.startsWith("GET")) {
			String QQNumber = null;
			try {
				QQNumber = new URL(line.split(" ")[1]).getQuery().split("&")[1].split("=")[1].split("_")[2];
				QQNumberSet.add(QQNumber);
				System.out.println(QQNumber);
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
		}
	}

	public void showSet() {
		for (String s : QQNumberSet) {
			System.out.println(s);
		}
	}

	public void showAsQQMail() {
		for (String s : QQNumberSet) {
			System.out.println(s + "@qq.com");
		}
	}

	public int getSize() {
		return QQNumberSet.size();
	}

	public List<String> getAsQQNumberList() {
		List<String> list = new ArrayList<String>();
		list.clear();
		list.addAll(QQNumberSet);
		return list;
	}

	public List<String> getAsQQMailList() {
		List<String> list = new ArrayList<String>();
		list.clear();
		for (String s : QQNumberSet) {
			list.add(s + "@qq.com");
		}
		return list;
	}
}
